<?
  class DataBase
  {
  	private static $host = 'localhost';
	private static $dbuser = 'sa';
	private static $dbpass = 'desarrollo';
	private static $dbname = 'thechurch';

   
    public static function ExecuteNonQuery($sql)
    {
      $link = mysql_connect(self::$host, self::$dbuser, self::$dbpass);
	  mysql_select_db(self::$dbname);
	  $res = mysql_query($sql);
	  $affected_rows = mysql_affected_rows($link);
	  mysql_close($link);
	  return $affected_rows;
    }
	
    public static function ExecuteQuery($sql, $mode="ROW")
    {
      $link = mysql_connect(self::$host, self::$dbuser, self::$dbpass);
	  mysql_select_db(self::$dbname);
	  $res = mysql_query($sql);
	  echo mysql_error();
	  
	  $results = array();
	  
	  if($mode=="ROW"){
			while($row = mysql_fetch_row($res))	  
				array_push($results, $row);	  
		}elseif($mode=="ARRAY"){
			 while($row = mysql_fetch_array($res))	  
				array_push($results, $row);	  
		}
	  
	  mysql_close($link);
	  
	  return $results;
    }
	
	public static function ExecuteScalar($sql)
    {
      $link = mysql_connect(self::$host, self::$dbuser, self::$dbpass);
	  mysql_select_db(self::$dbname);
	  $res = mysql_query($sql);	  
	  echo mysql_error();
	  
	 $row = mysql_fetch_row($res);
	  
	  mysql_close($link);	  
	  return $row[0];
    }
	
	public static function FieldsName($query)
	{	
      $link = mysql_connect(self::$host, self::$dbuser, self::$dbpass);
	  mysql_select_db(self::$dbname);

		$result = mysql_query($query);
		$Nfields = mysql_num_fields($result);
		$names = array();
		
		for ( $i = 0; $i < $Nfields; $i++ ) 
			array_push($names, mysql_field_name($result, $i));

		return $names;
	}#mysql_fields_name
	
	
	public static function ExecuteAndReturnResult($sql)
    {
      $link = mysql_connect(self::$host, self::$dbuser, self::$dbpass);
	  mysql_select_db(self::$dbname);
	  return $res = mysql_query($sql);
    }
	
	
	

  }#DataBase
?>